package com.mall.user.controller;


import com.mall.common.core.LoginUserHandler;
import com.mall.common.entity.ResponseData;
import com.mall.common.entity.UserDTO;
import com.mall.user.entity.param.UserAddParam;
import com.mall.user.entity.param.UserEditParam;
import com.mall.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wuyijie
 * @since 2021-06-20
 */
@RestController
@RequestMapping("/user")
@Api(value = "UserController", tags = "用户接口")
@Slf4j
public class UserController {
    @Autowired
    private IUserService userService;
    @Autowired
    private LoginUserHandler loginUserHandler;

    @RequestMapping(value = "/user", method = RequestMethod.POST)
    @ApiOperation(value = "add", notes = "添加方法")
    public ResponseData add(@Validated @RequestBody UserAddParam userAddParam) {
        UserDTO currentUser = loginUserHandler.getCurrentUser();
        log.info("currentUser: {}", currentUser);
        return ResponseData.success(userService.add(userAddParam));
    }

    @RequestMapping(value = "/user", method = RequestMethod.PUT)
    @ApiOperation(value = "edit", notes = "修改方法1")
    public ResponseData edit(@Validated @RequestBody UserEditParam userEditParam) {
        return ResponseData.success(userService.edit(userEditParam));
    }

}
